package cn.edu.neusoft.yuejian_02.model;

import java.util.List;

import cn.edu.neusoft.yuejian_02.bean.OrderBean;
import cn.edu.neusoft.yuejian_02.bean.UserBean;
import cn.edu.neusoft.yuejian_02.listener.RetrofitListener;
import cn.edu.neusoft.yuejian_02.service.AwardService;
import cn.edu.neusoft.yuejian_02.service.UserService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by jj on 2017/9/26.
 */

public class UserModel extends BaseModel{


    public void login(String username, String psssword,final RetrofitListener listener) {


        UserService userService = retrofit.create(UserService.class);
        Call call = userService.userLogin(username, psssword);
       call.enqueue(new Callback() {
           @Override
           public void onResponse(Call call, Response response) {
               UserBean userBean = (UserBean) response.body();
               listener.onSuccess(userBean);
           }

           @Override
           public void onFailure(Call call, Throwable t) {
               listener.onFail();
           }
       });
    }

    public void Reg(String username, String passsword,String nickname,String age,final RetrofitListener listener){

        //Toast.makeText(this,,Toast.LENGTH_SHORT).show();
        UserService userService=retrofit.create(UserService.class);
        Call call =  userService.userReg(username,passsword,nickname,age);
        call.enqueue(new Callback() {
            @Override
            public void onResponse(Call call, Response response) {
                UserBean userBean = (UserBean) response.body();
                listener.onSuccess(userBean);
            }

            @Override
            public void onFailure(Call call, Throwable t) {
                listener.onFail();
            }
        });
    }

    public Call UserInfo(String userid){

        //Toast.makeText(this,,Toast.LENGTH_SHORT).show();
        UserService userService=retrofit.create(UserService.class);
        return userService.userinfo(userid);

    }

    public Call Update(String userid, String nick, String age,String username,String tel){

        //Toast.makeText(this,,Toast.LENGTH_SHORT).show();
        UserService userService=retrofit.create(UserService.class);
        return userService.update(userid,nick,age,username,tel);
    }

    public void OrderList(String uid,String flag,final RetrofitListener listener){

        //Toast.makeText(this,,Toast.LENGTH_SHORT).show();
        UserService userService=retrofit.create(UserService.class);
       Call call = userService.orderlist(uid,flag);
        call.enqueue(new Callback() {
            @Override
            public void onResponse(Call call, Response response) {
                List<OrderBean> orderBeen = (List<OrderBean>) response.body();
                listener.onSuccess(orderBeen);
            }

            @Override
            public void onFailure(Call call, Throwable t) {
                listener.onFail();
            }
        });
    }
    public void getAward(String uid,String sportvalue,final RetrofitListener listener){

        //Toast.makeText(this,,Toast.LENGTH_SHORT).show();
        AwardService service=retrofit.create(AwardService.class);
        Call call = service.getAward(uid,sportvalue);
        call.enqueue(new Callback<UserBean>() {
            @Override
            public void onResponse(Call<UserBean> call, Response<UserBean> response) {
                UserBean userBean = (UserBean) response.body();
                listener.onSuccess(userBean);
            }

            @Override
            public void onFailure(Call<UserBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }


}
